#pragma once
#include <iostream>

using namespace std;


namespace gm
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;

		iterator begin()
		{
			return _str;
		}

		iterator end()
		{
			return _str + _size;
		}

		const_iterator begin() const
		{
			return _str;
		}

		const_iterator end() const
		{
			return _str + _size;
		}

		string(const char* str = "")
		{
			_size = strlen(str);
			_capacity = _size;
			_str = new char[_capacity + 1];

			strcpy(_str,str);
		}

		void swap(string & s)
		{
			std::swap(_str,s._str);
			std::swap(_capacity, s._capacity);
			std::swap(_size, s._size);
		}

		string(const string& s)
		{
			string tmp(s._str);
			swap(tmp);
		}

		string& operator = (string s)
		{
			swap(s);
			return *this;
		}

		~string()
		{
			delete[] _str;
			_capacity = _size = 0;
			_str = nullptr;
		}



	private:
		size_t _capacity;
		size_t _size;
		char* _str = nullptr;

		const static size_t npos = -1;
	};
}
